import pandas as pd
import os
import numpy as np
import mne
import torch
from sklearn.preprocessing import StandardScaler
#规范化特征数据
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

def transform_675(features,name):
    # features = np.array(features)
    features = pd.DataFrame(features)
    features = features.iloc[0]
    df = pd.read_csv("normal//{}.csv".format(name))
    mean = df.iloc[1]
    mean = mean.drop('Unnamed: 0', axis=0)
    mean = pd.to_numeric(mean)
    std = df.iloc[2]
    std = std.drop('Unnamed: 0', axis=0)
    std = pd.to_numeric(std)
    for i in range(len(features)):
        features[i] = ((features[i] - mean[i]) / std[i])
    #特征塑性
    features = features.values.reshape(1, -1)
    return features


def transform_spy(features):
    # features = np.array(features)
    features = pd.DataFrame(features)
    features = features.iloc[0]
    df = pd.read_csv("normal\\describe_SPY.csv")
    mean = df.iloc[1]
    mean = mean.drop('Unnamed: 0', axis=0)
    mean = pd.to_numeric(mean)
    print(mean)
    std = df.iloc[2]
    std = std.drop('Unnamed: 0', axis=0)
    std = pd.to_numeric(std)
    # print(std)
    # print(len(features))
    # print(features[1], mean[1], std[1])
    # print(((features[1] - mean[1]) / std[1]))
    for i in range(len(features)):
        features[i] = ((features[i] - mean[i]) / std[i])
    # features = features.values.reshape(1, -1)
    # print(features)
    features = features.values.reshape(1, -1)
    return features




def transform_DL(fes):
    len_window = 200 * 4
    element = fes.get_data()
    # print(data.shape)
    n_windows = element.shape[1] // len_window
    # print(n_windows)
    reshaped_X = np.reshape(element[:, :n_windows * len_window], (62, len_window, n_windows))
    X = reshaped_X.transpose((2, 1, 0))
    x_test_tensor = torch.from_numpy(X).to(torch.float32).to(device)
    return x_test_tensor



def transform_spy5(features):
    # features = np.array(features)
    features = pd.DataFrame(features)
    features = features.iloc[0]
    df = pd.read_csv("describe_spy5.csv")
    mean = df.iloc[1]
    mean = mean.drop('Unnamed: 0', axis=0)
    mean = pd.to_numeric(mean)
    # print(mean)
    std = df.iloc[2]
    std = std.drop('Unnamed: 0', axis=0)
    std = pd.to_numeric(std)
    # print(std)
    # print(len(features))
    # print(features[1], mean[1], std[1])
    # print(((features[1] - mean[1]) / std[1]))
    for i in range(len(features)):
        features[i] = ((features[i] - mean[i]) / std[i])
    # features = features.values.reshape(1, -1)
    # print(features)
    features = features.values.reshape(1, -1)
    return features